<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Jeesuite配置中心</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">

		<link rel="stylesheet" href="assets/plugins/layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="assets/css/global.css" media="all">
		<link rel="stylesheet" href="assets/plugins/font-awesome/css/font-awesome.min.css">
	</head>

	<body>
		<div class="layui-layout layui-layout-admin" style="border-bottom: solid 5px #f2f2f2;">
			<div class="layui-header header header-demo">
				<div class="layui-main">
					<div class="admin-login-box">
						<a class="logo" style="left: 0;" href="#">
							<span style="font-size: 22px;">Jeesuite配置中心</span>
						</a>
						<div class="admin-side-toggle">
							<i class="fa fa-bars" aria-hidden="true"></i>
						</div>
						<div class="admin-side-full">
							<i class="fa fa-life-bouy" aria-hidden="true"></i>
						</div>
					</div>
					<ul class="layui-nav admin-header-item">
						<li class="layui-nav-item">
							<a href="#" target="_blank">使用帮助</a>
						</li>
						<li class="layui-nav-item">
							<a href="javascript:;" class="admin-header-user">
								<img src="assets/images/head.jpg" />
								<span id="userName">admin</span>
								<span id="role" style="color: #FF5722;"></span>
							</a>
							<dl class="layui-nav-child">
								<dd>
									<a href="javascript:;" id="btn_edit_myinfo"><i class="fa fa-gear" aria-hidden="true"></i>编辑资料</a>
								</dd>
								<dd>
									<a href="javascript:;" id="btn_logout"><i class="fa fa-sign-out" aria-hidden="true"></i> 注销</a>
								</dd>
							</dl>
						</li>
					</ul>
				</div>
			</div>
			<div class="layui-side layui-bg-black" id="admin-side">
				<div class="layui-side-scroll" id="admin-navbar-side" lay-filter="side"></div>
			</div>
			<div class="layui-body" style="bottom: 0;border-left: solid 2px #f2f2f2;" id="admin-body">
				<div class="layui-tab admin-nav-card layui-tab-brief" lay-filter="admin-tab">
					<ul class="layui-tab-title">
						<li class="layui-this">
							<i class="fa fa-dashboard" aria-hidden="true"></i>
							<cite>控制面板</cite>
						</li>
					</ul>
					<div class="layui-tab-content" style="min-height: 150px; padding: 5px 0 0 0;">
						<div class="layui-tab-item layui-show">
							<iframe src="main.html"></iframe>
						</div>
					</div>
				</div>
			</div>
			<div class="layui-footer footer footer-demo" id="admin-footer">
				<div class="layui-main">
					<p>2016 &copy;
						<a href="http://www.jeesuite.com">jeesuite.com</a>
					</p>
				</div>
			</div>
			<div class="site-tree-mobile layui-hide">
				<i class="layui-icon">&#xe602;</i>
			</div>
			<div class="site-mobile-shade"></div>			
			<script type="text/javascript" src="assets/plugins/layui/layui.js"></script>
			<script type="text/javascript" src="assets/plugins/layui/lay/modules/jquery.js"></script>
			<script src="assets/js/index.js"></script>
			<script>
			var currentUser;
			layui.use(['layer','jeesuitelayui'], function() {
				var $ = layui.jquery,
					layer = layui.layer;
				$(function(){
					 $.getJSON('./user/login_user_info',function(data){
                   	　if(data.code == 200 && data.data ){
                   		currentUser = data.data;
                   		if(currentUser.type == 3 && (!currentUser.groupId || currentUser.groupId == 0)) {
							buildSelectGroupForm();
						}
                   		var role = '';
                   		if(currentUser.superAdmin){
                   			role = "(超级管理员)";
                   		}else if(currentUser.groupMaster){
                   			role = "(组负责人)";
                   		}else if(currentUser.groupAdmin){
                   			role = "(组管理员)";
                   		}
                   		$("#userName").html(currentUser.name);
                   		$("#role").html(role);
                   	　}else{
                   		location.href='login.html';
                   	　}
                   });
				});
				//
				$('#btn_edit_myinfo').on('click',function(){
					layer.open({
						  type: 2, 
						  title:'编辑资料',
						  content: './user/edit.html',
						  area: ['500px', '400px']
					}); 
				});
				//
				$('#btn_logout').on('click',function(){
					jeesuitelayui.post('/user/logout',{});
				});
			});

			function buildSelectGroupForm() {
				let html = '<form class="layui-form" action=""><div class="layui-form-item"><label class="layui-form-label">业务组列表</label><div class="layui-input-block">';
				layui.jquery.getJSON("../admin/group/options",function(res){
					if(res && res.length > 0) {
						res.forEach(item => {
							html = html + '<input type="radio" name="groupId" value="'+item.value+'" title="'+item.text+'">';
						});
					} else {
						content = "<h3>获取用户组信息失败</h3>";
					}
					html = html + '</div></div></form>';
					layer.open({
						type: 1
						,area: ['450px', '200px']
						,title: '选择业务组'
						,shade: 0.3 //遮罩透明度
						,maxmin: false //允许全屏最小化
						,anim: 1 //0-6的动画形式，-1不开启
						,content: html
						,btn: ['确认']
						,yes: function(index, layero){
							let $ = layui.jquery
							let groupId;
							$.each($("input[name='groupId']:checked"),function(){
								groupId = $(this).val();
							});
							//初次登陆设置业务组以及用户类型为普通用户
							layui.jeesuitelayui.post("../admin/user/update", {groupId: groupId}, function (res) {
								layui.jeesuitelayui.success("设置成功")
							})
							layer.close(index)
						}
					});
					layui.form.render();
				});
			}
			</script>
		</div>
	</body>

	<style>
		#groupList {
			margin-top: 20px;
			margin-left: 20px;
		}
		#groupList li {
			margin-top: 10px;
		}
	</style>

</html>